<?php
PageUtil::addVar("javascript","<script src=\"http://code.jquery.com/jquery.js\"></script>");
PageUtil::addVar("javascript","<script src=\"http://code.jquery.com/ui/1.10.3/jquery-ui.js\"></script>");
PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/brand.css\" rel=\"stylesheet\">");
?>
<div class="content_block col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<h2>จัดการยี่ห่อ <a style="float:right;" href="<?php echo base_url('admin/brand/add'); ?>" class="btn btn-primary"> Add </a></h2>
	 	<?php
	 	if(!empty($brands)){
	 	?>
	 		<table class="table table-hover">
		 		<thead>
					<tr>
						<th>รหัส</th>
						<th>ยี่ห้อ</th>
						<th>แก้ไข / ลบ </th>
					</tr>
				</thead>
				<tbody>
		 		<?php
		 		foreach($brands as $brand) {
		 		?>
				<tr>
					<td><?php echo $brand['id'];?></td>
					<td>
						<?php
				 			if(!empty($models[$brand['id']])){
				 				?>
				 				<a class='keep' children="children<?php echo $brand['id'];?>" href=''>
				 				<?php
				 			}
				 		?>
		 				<?php echo $brand['name']; ?>
		 				</a>
		 			</td>
					<td>
						<div class="btn-group">
							<a href="<?php echo base_url('admin/brand/addmodel/'.$brand ['id']);?>" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></a>
							<a href="<?php echo base_url('admin/brand/add/'.$brand ['id']);?>" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
		        	<a href="<?php echo base_url('admin/brand/delete/'.$brand ['id']);?>" class="btn btn-default" onClick="return confirm('คุณมั่นใจว่าจะลบ?');" ><span class="glyphicon glyphicon-remove"></span></a>
						</div>
					</td>
				</tr>
				<?php
					if(!empty($models[$brand['id']])){
						foreach ($models[$brand['id']] as $model) {				
				?>
					<tr class="children<?php echo $brand['id'];?> children">
						<td></td>
						<td>&nbsp;&nbsp;&nbsp;|_ <?php echo $model['name']; ?></td>
						<td>
							<div class="btn-group">
								<a href="<?php echo base_url('admin/model/add/'.$model ['id']);?>" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
			        	<a href="<?php echo base_url('admin/model/delete/'.$model ['id']);?>" class="btn btn-default" onClick="return confirm('คุณมั่นใจว่าจะลบ?');" ><span class="glyphicon glyphicon-remove"></span></a>
							</div>
						</td>
					</tr>
				<?php
						}
					}
				} // End foreach
				?>
				</tbody>
			</table>
		<?php
		}else{
			?>
				<div class="item-list">
	        <h4 class="text-center">ยังไม่มีข้อมูล</h4>
	      </div>
			<?php
		} // End if
		?>
</div>

<script type="text/javascript">
  $('a.keep').click(function () {
   	var cls = $(this).attr("children");
   	$("tr."+cls).toggle(200);
    return false;
  });

  $('tbody tr').each(function () {
  	if($(this).hasClass('children')){
  		$(this).toggle(200);
  	}
  });
</script>